﻿// This file is part of VideoLan.Inteop
//
// Copyright (C) 2008, Michael Melendez, http://www.MeediOS.com
//
//VideoLan.Inteop is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either 
//version 2.1 of the License, or (at your option) any later version.
//
//VideoLan.Inteop is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public 
//License along with this library.  If not, see <http://www.gnu.org/licenses/>.


using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace VideoLan
{
    internal class VlcEventManager
    {
        /// <summary>
        /// COM pointer to a vlc exception.  We will only use 1 exception pointer, 
        /// so we must always clear it out after use
        /// </summary>
        private libvlc_exception_t p_exception;

        private IntPtr p_event_manager;

        private List<VlcEventType> _AttachedEvents;

        internal VlcEventManager(IntPtr p_event_manager)
        {
            _AttachedEvents = new List<VlcEventType>();

            this.p_event_manager = p_event_manager;
            //Initalize our exception pointer
            p_exception = new libvlc_exception_t();
            p_exception.Initalize();           
        }

        internal void AttachEvent(VlcEventType EventType, VlcCallback Callback, IntPtr UserData)
        {
            InteropMethods.libvlc_event_attach(p_event_manager, EventType, Callback, UserData, ref p_exception);
            p_exception.CheckException();
            _AttachedEvents.Add(EventType);
        }
        internal void DetachEvent(VlcEventType EventType, VlcCallback Callback, IntPtr UserData)
        {
            InteropMethods.libvlc_event_detach(p_event_manager, EventType, Callback, UserData, ref p_exception);
            p_exception.CheckException();
            _AttachedEvents.Remove(EventType);
        }
        internal bool IsAttached(VlcEventType EventType)
        {
            return _AttachedEvents.Contains(EventType);
        }
    }
}
